home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 089a.dms / 089a.adf / TEXTS / CHAPTERS_21-30 / Chapter28.txt < prev    next >
Text File  |  1992-03-06  |  9KB  |  224 lines

  1.                      The Absolute Beginners Guide To Amos
  2.                     -------------------------------------
  3.                              Chapter Twenty Eight
  4.                              --------------------
  5.  
  6. We will now look at another program I wrote for Amoszine a while ago. 
  7. The program was just an example of how you can rip Amos ABK pictures out of
  8. an executable file and re-claim them as IFF pictures. 
  9. The Ripper uses quite a few new commands I haven't mentioned yet and which, 
  10. as usual, will be covered in detail.
  11.  
  12. The full program is contained in EXAMPLE28.Amos. What I suggest you should
  13. do is to make a test file for the ripper to use. Spack a few pictures into 
  14. some memory banks in Amos and compile and save the program as a Workbench
  15. executable. Load up Example28.Amos, Run it, and using the file selector
  16. select your "test file" and see your spacked pics get ripped right back into
  17. IFF picture files. Please do that now before reading on as you may not
  18. know what I am going on about.
  19.  
  20. I will just discuss the new commands and techniques used in the ripper
  21. program here.
  22.  
  23.  
  24.                            <:-------------------:>
  25.  
  26.  
  27. SET BUFFER 250
  28. --------------
  29. As the file the user will want to load is an executable file, it's going
  30. to be quite big so we must set aside a large chunk of memory using the 
  31. Set Buffer instruction. SET BUFFER has to be the very first command in your
  32.  program (except Rem's) otherwise an error will occur.
  33. See Chapter 16 for a few more details.
  34.  
  35. Here is the subroutine that loads in the executable file.
  36.  
  37. 'BLoad the file in using the file selector 
  38. '----------------------------------------- 
  39. _LOADPIC:
  40. F$=Fsel$("*.*","","LOAD EXE")
  41. If Length(10)>0 Then Erase 10
  42. Open In 1,F$ : BL=Lof(1)
  43. Reserve As Data 10,BL
  44. Close 1
  45. Bload F$,10
  46.  
  47.  
  48. The first new command we come across is LENGTH , this function returns the
  49. LENGTH in bytes of an Amos memory bank, in this case bank 10. What the
  50. above line is doing is checking to see if bank 10 has anything in it or not.
  51. If it has, then LENGTH will return the value, which will be more than 0 if 
  52. the bank has anything in it. If this is the case the bank is cleared using
  53. the ERASE 10 instruction.
  54. If LENGTH returned 0 then the second part of the line is ignored by Amos as 
  55. that  means the bank is already empty. Why bother checking? Because we are 
  56. going to reserve that bank to the size of the incoming file and if you try 
  57. to reserve a bank that isn't empty you will get a "Bank already reserved" 
  58. error.
  59.  
  60. RESERVE AS DATA is also an instruction we haven't looked at before. 
  61. This simply makes a bank any size we want. In this case we want the bank to
  62. be the size of the incoming file. As the file size can be anything from 60k 
  63. upwards we have to look at the file to interrogate it's size. This is done 
  64. by using the OPEN IN command. The 1 after OPEN IN is the channel number, 
  65. don't worry, the 1 is only for your reference as you can OPEN more than one 
  66. channel at a time. F$ is the name of the file selected by the user so 
  67. OPEN IN 1,F$ OPENs a channel to look at the file called F$. All this is done
  68. just so we can use the LOF function. LOF stands for Length Of File. In this 
  69. program we have assigned the variable BL to equal the Length of the file:
  70. BL=LOF(1), the 1 is the channel number. So now we have the correct info to
  71. Reserve bank 10 to the same length as the incoming file with:
  72.  
  73. Reserve As Data 10,BL 
  74.  
  75. The 10 is the bank number and BL the length. After using an OPEN IN 
  76. instruction you must always CLOSE the channel when you have finished using 
  77. it. CLOSE channel number. That's what the CLOSE 1 does.
  78.  
  79. BLOAD is very similar to other LOAD instruction except that BLOAD will not 
  80. check, alter, or interfere with the file in any way. For example, try 
  81. loading the same file into the Amos editor. Amos will report that 
  82. "This is not an Amos program". F$ as usual, is the file name to load and the
  83. 10 is the place we want the file to be loaded to (Bank 10)
  84.  
  85.  
  86. 'This is where we do all the searching 
  87. '------------------------------------- 
  88. _SEARCHPICS:
  89. SEARCH$="Pac"
  90. ADR=Hunt(Start(10)+COUNT To Start(10)+Length(10),SEARCH$)
  91. If ADR=0 Then Print "ALL DONE! NO (MORE) PICS FOUND" : Wait 120 : Return 
  92. If Peek(ADR+4)=80 and Peek(ADR+5)=105 and Peek(ADR+6)=99
  93. B$="PIC.PAC HEADER FOUND AT"+Str$(ADR)
  94. Print ,B$
  95. COUNT=ADR+100
  96. End If 
  97. Return
  98.  
  99. Search$ is a variable which will hold the text string we are searching for.
  100. In this case the beginning of a spacked memory bank header starts with "Pac" 
  101.  
  102. This will be passed to the HUNT function.
  103.  
  104. ADR is the variable I have tagged to the HUNT function to hold the result
  105. of the operation this will hold 0 if nothing has been found or the address
  106. of the "P" (in  "Pac") in memory. I will explain the PEEK function later.
  107.  
  108. We now have to tell HUNT exactly where to search for the "Pac" string by
  109. giving a start address and an end address. Start (10) means the first
  110. address of bank 10. The +COUNT bit is used in case we have already
  111. found a picture previously in the same search. If a pic is found and we
  112. re-call this routine it would start back at the beginning and keep finding
  113. the same picture. But if we record the address of the last pic found in the
  114. COUNT variable and add 100 to it then the search will resume just past the
  115. last found pic header. So if in the first pass HUNT found a picture at
  116. address 50000 then when Amos returned to continue searching for the next
  117. picture the search would start at START(10)+50100. If it started at 50000
  118. it would still catch the last picture found so we add 100 bytes to make sure
  119. it skips it.
  120.    
  121. 'Restore the picture to be a true Amos ABK pic 
  122. '--------------------------------------------- 
  123. _HEADER:
  124. '
  125. 'poke ABk at new start of bank  
  126. Poke ADR-12,65
  127. Poke ADR-11,109
  128. Poke ADR-10,66
  129. Poke ADR-9,107
  130. '
  131. 'restore some data  discarded by compiler
  132. Poke ADR-8,0
  133. Poke ADR-7,$A
  134. Poke ADR-6,0
  135. Poke ADR-5,0
  136. Poke ADR-4,$80
  137. Poke ADR-3,0
  138. Poke ADR-2,$1C
  139. Poke ADR-1,$32
  140. 'Guess length for now
  141. Bsave "ram:pic.abk",ADR-12 To ADR+72000
  142. Gosub _VIEWPIC
  143. Gosub _SAVEPIC
  144. Return 
  145.  
  146. The POKE instruction allows you to change the contents of memory. What we
  147. are doing in the above routine is POKEing what should be the correct 
  148. information to the ABK header of the picture. The form of the POKE command 
  149. works like this:
  150.  
  151. POKE Address,Value
  152.  
  153. Where the address is the memory location you want to change and the value is
  154. the new value you wish to change it to. POKE is simple to use but there is
  155. a lot more to it, you can't go poking anything anywhere or you will crash
  156. your program. 
  157. You may have noticed a $ as the value for some of the POKEs, that is a sign
  158. meaning that the following number is in Hexadecimal notation. We touched on
  159. Hex briefly in an earlier chapter. Also see the ASCII codes chart if you are
  160. interested in this part of the program. PEEK was used earlier in this
  161. program to read rather than write to an address in memory. PEEK is the 
  162. direct opposite to POKE. PEEK is used in the search part of this program to
  163. look for the string "Pac" byte by byte.  
  164.  
  165. After all that POKEing now we can actually "Cut out" the part of memory that
  166. we think is a spacked picture. The problem is knowing the length we need to
  167. cut out. When the Compiler does it's job it erases this important
  168. information so we have only one option and that is to cut out a huge lump.
  169. I decided on 72000 bytes (around 71K) as it's extremely unlikely that a
  170. spacked pic will be that large, the average spacked pic seems to be around
  171. 15K so if you are short on memory try lowering this figure.
  172.  
  173. As the aim of the program is to get the original IFF image in it's correct
  174. size we are far from finished. We save the pic to Ram: for temporary use.
  175.  
  176. As we are using the BSAVE instruction (See BLOAD) we have to tell Amos the 
  177. start address and the length. We know both of these figures. The Start 
  178. address will be ADR-12 (-12 bytes to include the new POKEs we have entered 
  179. to re-create the original header) The end address will be ADR+72000
  180. (The 72000 is a figure I just plucked out of the air)
  181.  
  182. OK, so far we have loaded an executable file, found what we hope is a
  183. spacked picture file (ABK) and have cut a copy of it out of memory and saved
  184. it to the Ram Disk.
  185.  
  186. Now let the user view the picture on screen.
  187.   
  188. 'Display picture if any found
  189. '----------------------------- 
  190. _VIEWPIC:
  191. Load "ram:pic.abk",11
  192. Unpack 11 To 0
  193. Wait 25
  194. While Mouse Key=0 : Wend 
  195. Return 
  196.  
  197. First we load the Abk file as if it were a normal Abk spacked picture file,
  198. which it is, now that we have modified it! We load it into bank 11.
  199.  
  200. Then UNPACK it to Screen 0 in the usual way and wait for a mouse click.
  201.  
  202. 'Let user save if
  203. '----------------- 
  204. _SAVEPIC:
  205. F$=Fsel$("*.*","","SAVE IFF")
  206. Save Iff F$,0
  207. Return
  208.  
  209. Now this is the crafty part, we let the user save the SCREEN out as a normal
  210. IFF picture file. Amos saves a copy of the screen and leaves all the
  211. extra wastage behind. So what was a 71K ABK file is now something like the
  212. original 20K IFF file which can now be treated as a normal picture.
  213.  
  214. After saving, the program then continues searching for more pics until the
  215. end of the bank is reached.
  216.  
  217. Remember, if the executable file has be crunched or squashed in any way the
  218. ripper will not be able to identify the pic's in it. Also, remember not all
  219. Amos programs contain Spacked memory banks.
  220.  
  221.  
  222.                          End of Chapter Twenty Eight
  223.                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  224.